﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CMN.BLL;
using CMN.Common;
using CMN.Entity;
using CMN.Models.Interfaces;
namespace CMN.Models
{
    /// <summary>
    /// 模板方案Service
    /// </summary>
    public class Normal_TemplatesService: ISearchDataService<Normal_TemplatesEntity>
    {
        /// <summary>
        /// 新增模板方案
        /// </summary>
        /// <param name="Normal_TemplatesEntity"></param>
        /// <returns>bool</returns>
        public string Insert(Normal_TemplatesEntity normal_templatesEntity)
        {
            Normal_Templates bll = new Normal_Templates();
            normal_templatesEntity.DataTable_Action = DataTableAction.Insert;
            if (bll.InsertUpdateDelete(normal_templatesEntity) > 0)
            {
                return "";
            }
            else
            {
                return "失败";
            }
        }

        /// <summary>
        /// 是否已存在模板
        /// </summary>
        /// <param name="dir"></param>
        /// <returns></returns>
        public int IsHas(string dir)
        {
            Normal_Templates bll = new Normal_Templates();
            return  bll.DirIsExist(dir);
        }
        /// <summary>
        /// 返回模板方案查询列表
        /// </summary>
        /// <param name="qp"></param>
        /// <param name="count">查询总个数</param>
        /// <returns>List</returns>
        public List<Normal_TemplatesEntity> List(QueryParam qp,out int count)
        {
            Normal_Templates bll = new Normal_Templates();
            return bll.List(qp, out count);
        }

        /// <summary>
        /// 更新模板方案
        /// </summary>
        /// <param name="Normal_Templates"></param>
        /// <returns>bool</returns>
        public string Update(Normal_TemplatesEntity normal_templatesEntity)
        {
            Normal_Templates bll = new Normal_Templates();
            normal_templatesEntity.DataTable_Action = DataTableAction.Update;
            if (bll.InsertUpdateDelete(normal_templatesEntity) > 0)
            {
                return "";
            }
            else
            {
                return "失败";
            }
        }

        /// <summary>
        /// 删除模板方案
        /// </summary>
        /// <param name="Normal_Templates"></param>
        /// <returns>bool</returns>
        public string Delete(Normal_TemplatesEntity normal_templatesEntity)
        {
            Normal_Templates bll = new Normal_Templates();
            normal_templatesEntity.DataTable_Action = DataTableAction.Delete;
            if (bll.InsertUpdateDelete(normal_templatesEntity) > 0)
            {
                Normal_TemplateList tempLst = new Normal_TemplateList();
                Normal_Skin normalSkin = new Normal_Skin();
                normalSkin.DelByTemplateId(normal_templatesEntity.Id.ToString());
                tempLst.DelByTemplateId(normal_templatesEntity.Id.ToString());
                return "";
            }
            else
            {
                return "失败";
            }
        }

        /// <summary>
        /// 批量删模板方案
        /// </summary>
        /// <param name="idList">删除id列表  2_8_9_45</param>
        /// <returns>bool</returns>
        public string DeleteList(string idList)
        {
            Normal_Templates bll = new Normal_Templates();
            string[] list =Utils.SplitString(idList,"_");
            string strDel=Utils.ArrayToString(list,",",false);
            if (bll.DelList(strDel) > 0)
            {
                return "";
            }
            else
            {
                return "失败";
            }

        }

        /// <summary>
        /// 返回单个模板方案
        /// </summary>
        /// <param name="id"></param>
        /// <returns>Normal_TemplatesEntity</returns>
        public Normal_TemplatesEntity Look(int id)
        {
            Normal_Templates bll = new Normal_Templates();
            return bll.Disp(id);
        }
    }
}
